<?php
include("db/connect.php");
include("funcsubstr.php");
switch($_GET["mode"]){
	case 1:
	$sql="update ordersmaterial set ordersmat_status='".$_GET["status"]."' where ordermat_id=".$_GET["orderid"];
	$query=mysql_query($sql);
	//echo $sql;
		break;
	case 2:
	$sql="update ordersmaterial set ordersmat_status='".$_GET["status"]."' where ordermat_id=".$_GET["orderid"];
	$query=mysql_query($sql);
	break;
	case 3:
	$sql="select *  from material,cartmaterial,ordersmaterial where material.mat_id=cartmaterial.mat_id and ordersmaterial.ordermat_id=cartmaterial.ordermat_id and ordersmat_status='".$_GET["status"]."' and mat_name like '%".$_GET["namemat"]."%'";
	$query=mysql_query($sql);
	?>
	<table width="100%" border="1">
    <tr>
      <th width="187">รหัสการสั่งซื้อวัตถุดิบ</th>
      <th width="89">วันที่สั่งซื้อ</th>
      <th width="113">ชื่อวัตถุดิบ</th>
      <th width="67">ราคา(บาท)</th>
      <th width="63">จำนวน(หน่วย)</th>
      <th width="130">ยอดรวม(บาท)</th>
          <?php if($_GET["status"]=="000"){ ?>
      <th width="147">อนุมัติการสั่งซื้อ</th>
      <th width="148">ยกเลิกการสั่งซื้อ</th>
<?php }?>
    </tr>
<?php 
  while($resultmaterial=mysql_fetch_array($query)){
	   $year=substr($resultmaterial["ordersmat_date"],0,4)+543;
		$month=monthconv(substr($resultmaterial["ordersmat_date"],5,2));
		$day=substr($resultmaterial["ordersmat_date"],8,2);
  ?>
    <tr>
      <td><?php echo $resultmaterial["ordermat_id"]?></td>
      <td><?php echo $day.' '.$month.' '.$year?></td>
      <td><?php echo $resultmaterial["mat_name"]?></td>
      <td><?php echo $resultmaterial["mat_price"]?></td>
      <td><?php echo ($resultmaterial["mat_qty"]."  ".$resultmaterial["mat_unit"])?></td>
      <td><?php echo number_format ($resultmaterial["mat_price"]*$resultmaterial["mat_qty"])?></td>
   <?php if($_GET["status"]=="000"){ ?>
      <td><a href="Javascript:materialUpdate(1,<?php echo $resultmaterial["ordermat_id"];?>);">ยื่นอนุมัติการสั่งซื้อ</a></td> 
      <td><a href="Javascript:materialUpdate(2,<?php echo $resultmaterial["ordermat_id"];?>);" >ลบ</a></td>
      <?php }?>
    </tr>
    <?php }?>
  </table>
	<?php
	break;
	
	}
?>



